#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import sys
import os
path = os.getcwd()
path = os.path.dirname(path)
sys.path.append(path)

import time
import datetime
import requests
import json

#url中的*.*.*.*指的是部署neo4j查询服务的服务器地址（跟neo4j数据库的地址相同）

def mode_get_1():
    """ get """
    url = "http://*.*.*.*:80/graph_search?subject=张伯苓&search_type=1"
    response = requests.request("GET", url)
    resp = response.text
    print(json.loads(resp))


def mode_post_1():
    """ post """
    url = "http://*.*.*.*:80/graph_search"
    payload = json.dumps({"subject": "张伯苓", "search_type": 1})
    headers = {'Content-Type': 'application/json'}
    response = requests.request("POST", url, headers=headers, data = payload)
    print(response.text)

def mode_get_2():
    """ get """
    url = "http://*.*.*.*:80/graph_search?subject=张伯苓&relation=民族&search_type=2"
    response = requests.request("GET", url)
    resp = response.text
    print(json.loads(resp))


def mode_post_2():
    """ post """
    url = "http://*.*.*.*:80/graph_search"
    payload = json.dumps({"subject": "张伯苓", "relation":"民族","search_type": 2})
    headers = {'Content-Type': 'application/json'}
    response = requests.request("POST", url, headers=headers, data = payload)
    print(response.text)

def mode_get_3():
    """ get """
    url = "http://*.*.*.*:80/graph_search?subject=张伯苓&relation=职业&object=教育家&search_type=3"
    response = requests.request("GET", url)
    resp = response.text
    print(json.loads(resp))


def mode_post_3():
    """ post """
    url = "http://*.*.*.*:80/graph_search"
    payload = json.dumps({"subject": "张伯苓", "relation":"职业", "object":"教育家", "search_type": 3})
    headers = {'Content-Type': 'application/json'}
    response = requests.request("POST", url, headers=headers, data = payload)
    print(response.text)

def mode_get_4():
    """ get """
    url = "http://*.*.*.*:80/graph_search?subject=张伯苓&object=天津&search_type=4"
    response = requests.request("GET", url)
    resp = response.text
    print(json.loads(resp))


def mode_post_4():
    """ post """
    url = "http://*.*.*.*:80/graph_search"
    payload = json.dumps({"subject": "张伯苓", "object":"天津", "search_type": 4})
    headers = {'Content-Type': 'application/json'}
    response = requests.request("POST", url, headers=headers, data = payload)
    print(response.text)

if __name__ == '__main__':
    start = time.time()

    #mode_get_4()
    mode_post_4()

    end = time.time()
    delta = end - start
    print("Finished time is {}".format(datetime.timedelta(seconds=delta)))
